﻿using Prism.Ioc;
using StarryEdge.Core;
using StarryEdge.Core.Manager;
using StarryEdge.Core.Parameter;
using StarryEdge.Core.Tool;
using StarryEdge.Parameter;
using StarryEdge.WPF.Lang;
using System;
using System.Windows;

namespace StarryEdge.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void MinimizeClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        private void MaximizeClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Maximized;
        }

        private void RestoreDownClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Normal;
        }

        private void CloseClick(object sender, RoutedEventArgs e)
        {
            var app = App.Current as App;
            if (app.Container.Resolve<ITemporaryParameter>().GetStatusSoftware())
            {
                IDialogHost dialogHost = app.Container.Resolve<IDialogHost>();
                dialogHost.DialogShow(LangManager.Instance.ToolTip["DoNotClose"], Core.Enums.LogLevel.Warning, hostDialog: Core.Enums.PopUpTypes.Global);
                return;
            }
            app.Container.Resolve<IUIRoleManage>().Save();
            KeyboardHook.Stop();
            Close();
        }

        private void WindowStateChanged(object sender, EventArgs e)
        {
            SetCaptionHeight();
        }

        private void HeaderSizeChanged(object sender, SizeChangedEventArgs e)
        {
            SetCaptionHeight();
        }

        private void SetCaptionHeight()
        {
            switch (WindowState)
            {
                case WindowState.Normal:
                    chrome.CaptionHeight = header.ActualHeight + BorderThickness.Top - chrome.ResizeBorderThickness.Top;
                    break;
                case WindowState.Maximized:
                    chrome.CaptionHeight = header.ActualHeight - BorderThickness.Top;
                    break;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Maximized;
        }
    }
}
